<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      label-width="68px"
    >
      <el-form-item label="会员等级" prop="memberLevel">
        <el-select
          v-model="queryParams.memberLevel"
          placeholder="请选择会员等级"
          clearable
          @change="memberLevelChange"
        >
          <el-option
            v-for="item in levelList"
            :key="item.value"
            :label="item.name"
            :value="item.value"
          >
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item prop="userId">
        <el-input
          v-model="queryParams.userId"
          placeholder="请输入ID/昵称/手机号"
          clearable
        />
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-table :data="pageList" highlight-current-row>
      <!-- <el-table-column label="会员ID" align="center" prop="id" width="80" /> -->
      <el-table-column label="昵称" align="center" prop="userName">
        <template slot-scope="scope">
          <div class="user-box">
            <el-image
              style="width: 50px; height: 50px; margin-right: 5px"
              :src="scope.row.avatar"
            ></el-image>
            <div>
              <div>{{ scope.row.nickName }}</div>
              <div>{{ scope.row.phonenumber }}</div>
            </div>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="会员类型" align="center" prop="userLevelName">
        <!-- <template slot-scope="scope">
          <div>{{ filterEnum(scope.row.type, levelList) }}</div>
        </template> -->
      </el-table-column>
      <el-table-column label="订单数" align="center" prop="orderCount" />
      <el-table-column label="订单金额" align="center" prop="orderPayMoney" />
      <el-table-column
        label="已完成订单数"
        align="center"
        prop="orderAccomplishCount"
      />
      <el-table-column
        label="已完成订单金额"
        align="center"
        prop="orderAccomplishPayMoney"
      />
    </el-table>

    <!-- total -->
    <pagination
      v-show="pageList.length > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { selectMemberDataPage } from "@/api/data/member";
export default {
  name: "Member",
  data() {
    return {
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        userId: null,
        memberLevel: null,
      },
      // 会员级别
      levelList: [
        {
          value: 0,
          name: "普通会员",
        },
        {
          value: 1,
          name: "VIP",
        },
        {
          value: 2,
          name: "SVIP",
        },
        {
          value: 3,
          name: "共享店主",
        },
        {
          value: 4,
          name: "联创",
        },
        {
          value: 5,
          name: "区域运营中心",
        },
        {
          value: 6,
          name: "总裁",
        },
      ],
      // 会员列表
      pageList: [],
      total: null,
    };
  },
  created() {
    this.getList();
  },
  mounted() {},
  methods: {
    // 查询会员数据列表
    getList() {
      this.loading = true;
      selectMemberDataPage(this.queryParams).then((response) => {
        this.pageList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    memberLevelChange(val) {
      console.log("val-----", val);
    },
    // 搜索按钮
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    // 重置按钮
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    filterEnum(value, enumData) {
      let filterData = {};
      if (Array.isArray(enumData)) {
        filterData = enumData.find((item) => item.value == value);
      }
      return filterData ? filterData.name : "";
    },
  },
};
</script>

<style lang="less" scoped>
.user-box {
  display: flex;
  justify-content: center;
}
</style>
